Back to course home
0% completed
Vote For New Content
Microsoft Hard Problems
Regular Expression Matching (hard)
Solution: Regular Expression Matching
First Missing Positive (hard)
Solution: First Missing Positive
Largest Rectangle in Histogram (hard)
Solution: Largest Rectangle in Histogram
Sliding Window Maximum (hard)
Solution: Sliding Window Maximum
Count Unique Characters of All Substrings of a Given String (hard)
Solution: Count Unique Characters of All Substrings of a Given String
Word Ladder (hard)
Solution: Word Ladder
Word Ladder II (hard)
Solution: Word Ladder II
Number of Flowers in Full Bloom (hard)
Solution: Number of Flowers in Full Bloom
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Delete Node in a BST (medium)
Problem Statement
Given a root node of the binary search tree, and an integer value key, return the root of the updated BST after deleting the node having a value equal to key.
If BST doesn't contain the node having value equal to key, return the same binary tree.
Examples
Example 1:
- Input:
[8, 3, 10, 1, 6, null, 14, null, null, 4, 7, 13], key =3
- Expected Output:
[8, 4, 10, 1, 6, null, 14, null, null, null, 7, 13] - Justification: After removing the node with value
3, its right subtree's smallest value (4) replaces it to maintain the BST structure.
Example 2:
- Input:
[20, 10, 30, null, 15, 25, 35], key =10
- Expected Output:
[20, 15, 30, null, null, 25, 35] - Justification: The node
10is removed and replaced by its right child15to keep the tree's integrity.
Example 3:
- Input:
[50, 30, 70, 20, 40, 60, 80], key =10
- Expected Output:
[50, 30, 70, 20, 40, 60, 80] - Justification: The BST doesn't contain the node with value 10. So, it returns the original BST.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Spiral Matrix
Solution: Delete Node in a BST
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself